package com.scott.java8concurrency.java7;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;

/**
 * Fork / Join 示例
 *
 * @author Scott
 * @see ForkJoinPool
 */
public class ForkJoinDemo {
    public static void main(String[] args) {
        //并行：多核参与
        //并发：一同参与
        //ForkJoin 线程池
        System.out.printf("当前公用的ForkJoin线程池并行数：%s\n", ForkJoinPool.commonPool().getParallelism());
        System.out.printf("当前CPU处理器数：%d：\n", Runtime.getRuntime().availableProcessors());

        //与 ThreadPoolExecutor 类似
        ForkJoinPool forkJoinPool = new ForkJoinPool();


        forkJoinPool.invoke(new RecursiveAction() {


            @Override
            protected void compute() {
                System.out.printf("迭代计算方法\n");
            }
        });

        forkJoinPool.shutdown();
    }
}
